package com.terrynoya.fight.combat
{
	import com.terrynoya.fight.char.Character;

	public class OffensiveInfo
	{
		private var _hitDef:HitDefinition;
		private var _chara:Character;
		private var _hitPauseTime:int;
		private var _hitCount:int;
		private var _activeHitDef:Boolean;
		private var _moveContact:int;
		private var _targetList:Array;
		private var _projecTileInfo:ProjectileInfo;
		private var _moveHit:int;
		
		public function OffensiveInfo(chara:Character)
		{
			this._chara = chara;	
			this._activeHitDef = false;
			this._hitDef = new HitDefinition();
			this._hitPauseTime = 0;
			this._hitCount = 0;
			this._targetList = new Array();
			this._projecTileInfo = new ProjectileInfo();
		}
		
		public function get moveHit():int
		{
			return _moveHit;
		}

		public function set moveHit(value:int):void
		{
			_moveHit = value;
		}

		public function get projecTileInfo():ProjectileInfo
		{
			return _projecTileInfo;
		}

		public function get targetList():Array
		{
			return _targetList;
		}

		public function set targetList(value:Array):void
		{
			_targetList = value;
		}

		public function get moveContact():int
		{
			return _moveContact;
		}

		public function set moveContact(value:int):void
		{
			_moveContact = value;
		}

		public function get hitCount():int
		{
			return _hitCount;
		}

		public function set hitCount(value:int):void
		{
			_hitCount = value;
		}

		public function get activeHitDef():Boolean
		{
			return _activeHitDef;
		}

		public function set activeHitDef(value:Boolean):void
		{
			_activeHitDef = value;
		}

		public function update():void
		{
			this.projecTileInfo.update();
			
			if(this._moveContact > 0)
			{
				this._moveContact ++;
			}
			if(this.moveHit > 0)
			{
				this._moveHit++;
			}
		}
		
		public function get hitPauseTime():int
		{
			return _hitPauseTime;
		}

		public function set hitPauseTime(value:int):void
		{
			_hitPauseTime = value;
		}

		public function onHit(hitDef:HitDefinition,target:Character,blocked:Boolean):void
		{
			this.addToTargetList(target);
			
			if(blocked)
			{
				this.moveContact = 1;
				this.moveHit = 0;
				this.hitPauseTime = hitDef.guardHitTime;
			}
			else
			{
				this.moveContact = 1;
				this.moveHit = 1;
				this.hitPauseTime = hitDef.pauseTime;
			}
		}
		
		private function addToTargetList(target:Character):void
		{
			if(this._targetList.indexOf(target) != -1)
			{
				return;
			}
			this._targetList.push(target);
		}
		
		public function removeFromTargetList(target:Character):void
		{
			var index:int = this._targetList.indexOf(target);
			this._targetList.splice(index,1);
		}

		public function get hitDef():HitDefinition
		{
			return _hitDef;
		}

		public function set hitDef(value:HitDefinition):void
		{
			_hitDef = value;
		}

	}
}